export default {
	install: function(Vue) {
		const versions = "versions1v=VMMVM13"
		Vue.prototype.version = versions
		Vue.prototype.isJSON = function(str) {
			if (typeof str === "string") {
				try {
					var obj = JSON.parse(str);
					if (typeof obj === "object" && obj) {
						return true;
					} else {
						return false;
					}
				} catch (e) {
					return false;
				}
			}
		};
		Vue.prototype.getUrlKey = function(name) {
			return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[
				1].replace(/\+/g, '%20')) || null
		};
		// 图片整合
		Vue.prototype.combImg = function(main, detail) {
			const img = [];
			if (main && detail) {
				return (main + ',' + detail).split(',')
			} else if (main && !detail) {
				return main.split(',')
			} else if (!main && detail) {
				return detail.split(',')
			} else {
				return img
			}
		};
		// 计算星期几
		Vue.prototype.dateMode = function(myDate, format) {
			const mode = format || "";
			let wk = myDate.getDay()
			let yy = String(myDate.getFullYear())
			let mm = myDate.getMonth() + 1 < 10 ? '0' + parseInt(myDate.getMonth() + 1) : parseInt(myDate.getMonth() + 1);
			let dd = String(myDate.getDate() < 10 ? '0' + myDate.getDate() : myDate.getDate())
			let hou = String(myDate.getHours() < 10 ? '0' + myDate.getHours() : myDate.getHours())
			let min = String(myDate.getMinutes() < 10 ? '0' + myDate.getMinutes() : myDate.getMinutes())
			let sec = String(myDate.getSeconds() < 10 ? '0' + myDate.getSeconds() : myDate.getSeconds())
			let weeks = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
			let week = weeks[wk]
			if (mode === 'week') {
				return week + '(' + mm + '/' + dd + ')';
			} else if (mode === 'weeks') {
				return week
			} else if (mode === 'nowDate') {
				return yy + '-' + mm + '-' + dd;
			} else {
				return yy + '-' + mm + '-' + dd + "" + hou + ':' + min + ':' + sec;
			}
		}
		// 备餐状态
		Vue.prototype.preparaStatus = function(type) {
			switch (parseInt(type)) {
				case 1:
					return "备货中";
				case 2:
					return "待送货";
				case 3:
					return "待回收";
				case 4:
					return "已完成";
				default:
					return type;
			}
		}
		// 状态
		Vue.prototype.pickUpStatus = function(type) {
			switch (parseInt(type)) {
				case 1:
					return "补货";
				case 2:
					return "回收";
				case 3:
					return "取货";
				default:
					return type;
			}
		}
		Vue.prototype.colorClass = function(type) {
			switch (parseInt(type)) {
				case 1:
					return "orange";
				case 2:
					return "gray";
				case 3:
					return "blue";
				default:
					return "gray";
			}
		}
		Vue.prototype.platoonStatus = function(type) {
			switch (parseInt(type)) {
				case 1:
					return "暂存";
				case 2:
					return "待确认";
				case 3:
					return "已退回";
				case 4:
					return "已确认";
				case 5:
					return "已确认";
				default:
					return type;
			}
		}
		Vue.prototype.colorClass_1 = function(type) {
			switch (parseInt(type)) {
				case 2:
					return "blue";
				case 3:
					return "orange";
				default:
					return "gray";
			}
		}
		//校验手机格式
		Vue.prototype.checkMobile = function(mobile) {
			return RegExp(/^1[3456789]\d{9}$/).test(mobile);
		}
		// 校验纯数字
		Vue.prototype.characterMath = function(chart) {
			return RegExp(/^\d{1,}$/).test(chart);
		}
		// 校验纯字母
		Vue.prototype.letterMath = function(letter) {
			return RegExp(/^[A-Za-z]+$/).test(letter);
		}
		// 后端校验
		Vue.prototype.allMath = function(letter) {
			return RegExp(/^(?:\d*|[a-zA-Z]*|[\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]*)$/).test(letter);
		}
		Vue.prototype.pay = function(item) {
			// 初始化,模式：测试test，正式prod
			Jnpay.init("test");
			// var r = confirm("是否发起支付")
			// if (r == true) {
			// 执行支付
			Jnpay.doPay({
				// 店铺ID：长整型
				storeId: 1568270699640844, //测试
				// storeId: 1583119219481033, //正式
				// 支付金额，小数2位
				price: item.price,
				// 商品名称
				goodName: "福福餐饮",
				// 支付成功的异步回调地址
				serverUrl: "http://tv.kdtyun.com/ad1/public/index.php?s=api/paytest/getPayResult/token/" + item.token +
					'/type/1',
				// 支付方式，仅支持：微信wechat，支付宝alipay
				payMode: "wechat",
				// 支付成功后页面重定向路径
				successPageUrl: "http://csb.stqcm.com/lunch/pages/order/index?statu=1" + '&' + versions,
				// 支付失败后页面重定向路径
				errorPageUrl: "http://csb.stqcm.com/lunch/pages/order/index?statu=2" + '&' + versions
			});
			// }
			var hasShare = true;
			/* begin禁用微信分享功能 */
			function funonBridgeReady() {
				WeixinJSBridge.call('hideOptionMenu');
			}
			if (!hasShare) {
				if (typeof WeixinJSBridge == "undefined") {
					if (document.addEventListener) {
						document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
					} else if (document.attachEvent) {
						document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
						document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
					}
				} else {
					onBridgeReady();
				}
			}
			/* end禁用微信分享功能 */
		}
		Vue.prototype.pay2 = function(item) {
			// 初始化,模式：测试test，正式prod
			Jnpay.init("test");
			// var r = confirm("是否发起支付")
			// if (r == true) {
			// 执行支付
			Jnpay.doPay({
				// 店铺ID：长整型
				storeId: 1568270699640844, //测试
				// storeId: 1583119219481033, //正式
				// 支付金额，小数2位
				price: item.price,
				// 商品名称
				goodName: "福福餐饮",
				// 支付成功的异步回调地址
				serverUrl: "http://tv.kdtyun.com/ad1/public/index.php?s=api/paytest/getPayResult/token/" + item.token +
					'/type/2',
				// 支付方式，仅支持：微信wechat，支付宝alipay
				payMode: "wechat",
				// 支付成功后页面重定向路径
				successPageUrl: "https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzA4MDQ2NDc1NQ==#wechat_redirect",
				// 支付失败后页面重定向路径
				errorPageUrl: "http://csb.stqcm.com/lunch/pages/android-pay/pay-status?status=2" + '&' + versions
			});
			// }
			var hasShare = true;
			/* begin禁用微信分享功能 */
			function funonBridgeReady() {
				WeixinJSBridge.call('hideOptionMenu');
			}
			if (!hasShare) {
				if (typeof WeixinJSBridge == "undefined") {
					if (document.addEventListener) {
						document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
					} else if (document.attachEvent) {
						document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
						document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
					}
				} else {
					onBridgeReady();
				}
			}
			/* end禁用微信分享功能 */
		}
		Vue.prototype.eqStatus = function(statu) {
			switch (parseInt(statu)) {
				case 1:
					return "关机";
				case 2:
					return "正常";
				case 3:
					return "故障";
				default:
					return statu;
			}
		}
		Vue.prototype.orderType = function(status, type) {
			if (type === 3) {
				return "已失效";
			} else if (type === 1) {
				return "待支付";
			} else if (type === 2 && status === 1) {
				return "待取餐";
			} else if (type === 2 && status === 3) {
				return "已逾期";
			} else if (type === 2 && status === 2) {
				return "已完成";
			}
		}
		Vue.prototype.opinionType = function(type) {
			switch (parseInt(type)) {
				case 1:
					return "系统问题反馈";
				case 2:
					return "商品问题反馈";
				case 3:
					return "流程问题反馈";
				case 4:
					return "其他问题反馈";
				case 5:
					return "我想吃";
				default:
					return "";
			}
		}
	}
};
